<?php

/**
 * @author Pwint Phyu Shwe
* Profile Controller
*
* Maps to the following url
* http://domain/index.php/profile
* or
* http://domain/index.php/profile/index
*/
class Message extends CI_Controller {
	function __construct() {
		parent::__construct();
                //check session
         $this->session->set_userdata(array('redirectUrl' =>current_url()));
         check_user_login();
	}
    function send(){
        $data['title'] = 'Broadcast Message in Portal';
        $data['action'] = 'admin/message/broadcast';
        $this->load->view('admin/broadcast_view', $data);
    }
    function broadcastAllUsers(){
       $body = $_POST['body'];
       $userid = $_POST['userid'];
       $subject = $_POST['subject'];

       $status = array("STATUS"=>"false", "result"=> $body. $userid . $subject);
       if(isset($subject)){
        $bc['subject'] = $subject;
        $bc['body']= $body;
        $bc['senderID'] = $userid;
        $this->load->model('Broadcast_model','',TRUE);
        $insertBroadcast =  $this->Broadcast_model->save($bc);
        $status =  $insertBroadcast;
       }
       echo json_encode ($status) ;
    }
	//view details
	function details(){
		$data['id']=$_POST['id'];
		 $status = array("STATUS"=>"false");
         if ($data['id']){

            $this->load->model('Broadcast_model','',TRUE);
            $messageDetails =  $this->Broadcast_model->get_data($data);
            $status =  $messageDetails;
           }
            echo json_encode ($status) ;
	}
	
    
    //get all the broadcast messsage by userid
    function oldbroadcasts(){
         $userid = $_POST['userid'];
          $status = array("STATUS"=>"false");
         if (isset($userid)){
             $this->load->model('Broadcast_model','',TRUE);
             $cond['senderID'] = $userid;
             $old_broadcasts =  $this->Broadcast_model->get_data($cond);
             $status = $old_broadcasts;
         }
         echo json_encode($status);

    }

    //broadcast message
    function messages() {
        $userid = $this->session->userdata('userid');
        //photo attachment
        //do upload
           /** if (isset($_FILES['userfile']['tmp_name']) && !empty($_FILES['userfile']['tmp_name'])) {
                $image_url = upload_files();
                if($image_url){
                    $urls = array_values($image_url);
                    $user['image_url'] = isset($urls[0]) ? $urls[0] : null;;
                    }else{
                        $data = array('message' => $this->upload->display_errors(), 'action' => 'admin/dashboard/broadcast');
                        $this->load->view('admin/broadcast_view', $data);
                    }
            }**/
        $this->load->model('Broadcast_model','' , TRUE);
        $data['messages'] = $this->Broadcast_model->get_other_msg($userid);
        $data ['title'] = "Message box";
        $this->load->view('/admin/messages_view', $data);



    }
	
	
}
?>